package com.picturetransform.binarization;


import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.util.Log;

public class PictureBinarization {

	static {  
	    System.loadLibrary("native");  
	}
	private native void transform(int [] bmp, int width, int height);

	private int[] dst;
	
	public Bitmap adaptiveBinarization(Bitmap srcBmp) {
		int height = srcBmp.getHeight();
		int width = srcBmp.getWidth();
		
		dst = new int[(width)*(height)+height];
		int i=0,j=0;

		for (i = 0; i < width; i++) {
			for (j = 0; j < height; j++) {
				dst[i*height+j]=srcBmp.getPixel(i,j);
			} 
		}
		Config conf = srcBmp.getConfig();
		srcBmp = null;
		Bitmap imgIn = Bitmap.createBitmap(width, height, conf);
		
		transform(dst, width, height);
		long start = System.currentTimeMillis();
		
		for (i = 0; i < width; i++) {
			for ( j = 0; j < height; j++) {
				imgIn.setPixel(i, j, dst[i*height+j]);
			}
		}
		dst = null;
		
		long stop = System.currentTimeMillis();
		
		Log.d("czas: ", (stop-start)+"");
		
		return imgIn;
	}
}
